﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using DAO;
using DTO;

namespace BUS
{
    public class PhieuMua_BUS
    {
        private static PhieuMua_BUS m_instance = null;

        public static PhieuMua_BUS Instance
        {
            get
            {
                if (m_instance == null)
                    m_instance = new PhieuMua_BUS();
                return m_instance;
            }
        }

        /// <summary>
        /// Lấy mã phiếu bán mua hàng lớn nhất
        /// </summary>
        /// <returns></returns>
        public string LayMaPhieuBanHangMax()
        {
            DataTable dt = PhieuMua_DAO.Instance.LayMaPhieuMuaHangMax();
            // Bi loi
            if (dt == null)
                return null;

            DataRowCollection list = dt.Rows;
            if (list.Count == 0)
                return "n/a";

            DataRow row = list[0];
            string maphieu = (string)row["MaPhieuMuaHang"];

            return maphieu;
        }

        /// <summary>
        /// Thêm phiếu mua hàng mới
        /// </summary>
        /// <param name="phieu"></param>
        /// <returns></returns>
        public bool ThemPhieuMuaHangMoi(PhieuMua_DTO phieu)
        {
            return PhieuMua_DAO.Instance.ThemPhieuMuaHangMoi(phieu.NgayMua.ToString(), phieu.NgayThanhToan.ToString(), phieu.MaKhachHang, phieu.TongTien);
        }
        
    }
}
